.class public Lrexsee/security/RexseeKeyPairGenerator;
.super Ljava/lang/Object;
.source "RexseeKeyPairGenerator.java"

# interfaces
.implements Lrexsee/core/browser/clazz/JavascriptInterface;


# static fields
.field private static final INTERFACE_NAME:Ljava/lang/String; = "KeyPairGenerator"


# instance fields
.field private final mBrowser:Lrexsee/core/browser/Browser;

.field private mPrivateKey:Ljava/lang/String;

.field private mPublicKey:Ljava/lang/String;


# direct methods
.method public constructor <init>(Lrexsee/core/browser/Browser;)V
    .locals 1
    .param p1, "browser"    # Lrexsee/core/browser/Browser;

    .prologue
    const/4 v0, 0x0

    .line 36
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 40
    iput-object v0, p0, Lrexsee/security/RexseeKeyPairGenerator;->mPublicKey:Ljava/lang/String;

    .line 41
    iput-object v0, p0, Lrexsee/security/RexseeKeyPairGenerator;->mPrivateKey:Ljava/lang/String;

    .line 37
    iput-object p1, p0, Lrexsee/security/RexseeKeyPairGenerator;->mBrowser:Lrexsee/core/browser/Browser;

    .line 38
    return-void
.end method


# virtual methods
.method public generateDSAKeyPair(I)Z
    .locals 5
    .param p1, "keySize"    # I

    .prologue
    const/4 v4, 0x0

    .line 59
    const/16 v3, 0x100

    if-lt p1, v3, :cond_0

    const/16 v3, 0x800

    if-gt p1, v3, :cond_0

    rem-int/lit8 v3, p1, 0x40

    if-eqz v3, :cond_1

    :cond_0
    move v3, v4

    .line 68
    :goto_0
    return v3

    .line 61
    :cond_1
    :try_start_0
    const-string v3, "DSA"

    invoke-static {v3}, Ljava/security/KeyPairGenerator;->getInstance(Ljava/lang/String;)Ljava/security/KeyPairGenerator;

    move-result-object v2

    .line 62
    .local v2, "keyPairGen":Ljava/security/KeyPairGenerator;
    invoke-virtual {v2, p1}, Ljava/security/KeyPairGenerator;->initialize(I)V

    .line 63
    invoke-virtual {v2}, Ljava/security/KeyPairGenerator;->generateKeyPair()Ljava/security/KeyPair;

    move-result-object v1

    .line 64
    .local v1, "keyPair":Ljava/security/KeyPair;
    invoke-virtual {v1}, Ljava/security/KeyPair;->getPublic()Ljava/security/PublicKey;

    move-result-object v3

    invoke-static {v3}, Lrexsee/security/RexseeSecurity;->key2string_(Ljava/security/Key;)Ljava/lang/String;

    move-result-object v3

    iput-object v3, p0, Lrexsee/security/RexseeKeyPairGenerator;->mPublicKey:Ljava/lang/String;

    .line 65
    invoke-virtual {v1}, Ljava/security/KeyPair;->getPrivate()Ljava/security/PrivateKey;

    move-result-object v3

    invoke-static {v3}, Lrexsee/security/RexseeSecurity;->key2string_(Ljava/security/Key;)Ljava/lang/String;

    move-result-object v3

    iput-object v3, p0, Lrexsee/security/RexseeKeyPairGenerator;->mPrivateKey:Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 66
    const/4 v3, 0x1

    goto :goto_0

    .line 67
    .end local v1    # "keyPair":Ljava/security/KeyPair;
    .end local v2    # "keyPairGen":Ljava/security/KeyPairGenerator;
    :catch_0
    move-exception v3

    move-object v0, v3

    .local v0, "e":Ljava/lang/Exception;
    move v3, v4

    .line 68
    goto :goto_0
.end method

.method public generateDsaPrivateKey(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 8
    .param p1, "prime"    # Ljava/lang/String;
    .param p2, "subPrime"    # Ljava/lang/String;
    .param p3, "base"    # Ljava/lang/String;
    .param p4, "privateKey"    # Ljava/lang/String;

    .prologue
    .line 120
    :try_start_0
    new-instance v3, Ljava/math/BigInteger;

    invoke-direct {v3, p1}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V

    .line 121
    .local v3, "p":Ljava/math/BigInteger;
    new-instance v4, Ljava/math/BigInteger;

    invoke-direct {v4, p2}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V

    .line 122
    .local v4, "q":Ljava/math/BigInteger;
    new-instance v1, Ljava/math/BigInteger;

    invoke-direct {v1, p3}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V

    .line 123
    .local v1, "g":Ljava/math/BigInteger;
    new-instance v5, Ljava/math/BigInteger;

    invoke-direct {v5, p4}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V

    .line 124
    .local v5, "x":Ljava/math/BigInteger;
    const-string v6, "DSA"

    invoke-static {v6}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;

    move-result-object v6

    new-instance v7, Ljava/security/spec/DSAPrivateKeySpec;

    invoke-direct {v7, v5, v3, v4, v1}, Ljava/security/spec/DSAPrivateKeySpec;-><init>(Ljava/math/BigInteger;Ljava/math/BigInteger;Ljava/math/BigInteger;Ljava/math/BigInteger;)V

    invoke-virtual {v6, v7}, Ljava/security/KeyFactory;->generatePrivate(Ljava/security/spec/KeySpec;)Ljava/security/PrivateKey;

    move-result-object v2

    .line 125
    .local v2, "key":Ljava/security/PrivateKey;
    invoke-static {v2}, Lrexsee/security/RexseeSecurity;->key2string_(Ljava/security/Key;)Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v6

    .line 127
    .end local v1    # "g":Ljava/math/BigInteger;
    .end local v2    # "key":Ljava/security/PrivateKey;
    .end local v3    # "p":Ljava/math/BigInteger;
    .end local v4    # "q":Ljava/math/BigInteger;
    .end local v5    # "x":Ljava/math/BigInteger;
    :goto_0
    return-object v6

    .line 126
    :catch_0
    move-exception v6

    move-object v0, v6

    .line 127
    .local v0, "e":Ljava/lang/Exception;
    new-instance v6, Ljava/lang/StringBuilder;

    const-string v7, "[Exception]"

    invoke-direct {v6, v7}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v0}, Ljava/lang/Exception;->getLocalizedMessage()Ljava/lang/String;

    move-result-object v7

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    goto :goto_0
.end method

.method public generateDsaPublicKey(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 8
    .param p1, "prime"    # Ljava/lang/String;
    .param p2, "subPrime"    # Ljava/lang/String;
    .param p3, "base"    # Ljava/lang/String;
    .param p4, "publicKey"    # Ljava/lang/String;

    .prologue
    .line 108
    :try_start_0
    new-instance v3, Ljava/math/BigInteger;

    invoke-direct {v3, p1}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V

    .line 109
    .local v3, "p":Ljava/math/BigInteger;
    new-instance v4, Ljava/math/BigInteger;

    invoke-direct {v4, p2}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V

    .line 110
    .local v4, "q":Ljava/math/BigInteger;
    new-instance v1, Ljava/math/BigInteger;

    invoke-direct {v1, p3}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V

    .line 111
    .local v1, "g":Ljava/math/BigInteger;
    new-instance v5, Ljava/math/BigInteger;

    invoke-direct {v5, p4}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V

    .line 112
    .local v5, "y":Ljava/math/BigInteger;
    const-string v6, "DSA"

    invoke-static {v6}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;

    move-result-object v6

    new-instance v7, Ljava/security/spec/DSAPublicKeySpec;

    invoke-direct {v7, v5, v3, v4, v1}, Ljava/security/spec/DSAPublicKeySpec;-><init>(Ljava/math/BigInteger;Ljava/math/BigInteger;Ljava/math/BigInteger;Ljava/math/BigInteger;)V

    invoke-virtual {v6, v7}, Ljava/security/KeyFactory;->generatePublic(Ljava/security/spec/KeySpec;)Ljava/security/PublicKey;

    move-result-object v2

    .line 113
    .local v2, "key":Ljava/security/PublicKey;
    invoke-static {v2}, Lrexsee/security/RexseeSecurity;->key2string_(Ljava/security/Key;)Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v6

    .line 115
    .end local v1    # "g":Ljava/math/BigInteger;
    .end local v2    # "key":Ljava/security/PublicKey;
    .end local v3    # "p":Ljava/math/BigInteger;
    .end local v4    # "q":Ljava/math/BigInteger;
    .end local v5    # "y":Ljava/math/BigInteger;
    :goto_0
    return-object v6

    .line 114
    :catch_0
    move-exception v6

    move-object v0, v6

    .line 115
    .local v0, "e":Ljava/lang/Exception;
    new-instance v6, Ljava/lang/StringBuilder;

    const-string v7, "[Exception]"

    invoke-direct {v6, v7}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v0}, Ljava/lang/Exception;->getLocalizedMessage()Ljava/lang/String;

    move-result-object v7

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    goto :goto_0
.end method

.method public generateRSAKeyPair(I)Z
    .locals 5
    .param p1, "keySize"    # I

    .prologue
    const/4 v4, 0x0

    .line 46
    const/16 v3, 0x100

    if-lt p1, v3, :cond_0

    const/16 v3, 0x800

    if-gt p1, v3, :cond_0

    rem-int/lit8 v3, p1, 0x40

    if-eqz v3, :cond_1

    :cond_0
    move v3, v4

    .line 55
    :goto_0
    return v3

    .line 48
    :cond_1
    :try_start_0
    const-string v3, "RSA"

    invoke-static {v3}, Ljava/security/KeyPairGenerator;->getInstance(Ljava/lang/String;)Ljava/security/KeyPairGenerator;

    move-result-object v2

    .line 49
    .local v2, "keyPairGen":Ljava/security/KeyPairGenerator;
    invoke-virtual {v2, p1}, Ljava/security/KeyPairGenerator;->initialize(I)V

    .line 50
    invoke-virtual {v2}, Ljava/security/KeyPairGenerator;->generateKeyPair()Ljava/security/KeyPair;

    move-result-object v1

    .line 51
    .local v1, "keyPair":Ljava/security/KeyPair;
    invoke-virtual {v1}, Ljava/security/KeyPair;->getPublic()Ljava/security/PublicKey;

    move-result-object v3

    invoke-static {v3}, Lrexsee/security/RexseeSecurity;->key2string_(Ljava/security/Key;)Ljava/lang/String;

    move-result-object v3

    iput-object v3, p0, Lrexsee/security/RexseeKeyPairGenerator;->mPublicKey:Ljava/lang/String;

    .line 52
    invoke-virtual {v1}, Ljava/security/KeyPair;->getPrivate()Ljava/security/PrivateKey;

    move-result-object v3

    invoke-static {v3}, Lrexsee/security/RexseeSecurity;->key2string_(Ljava/security/Key;)Ljava/lang/String;

    move-result-object v3

    iput-object v3, p0, Lrexsee/security/RexseeKeyPairGenerator;->mPrivateKey:Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 53
    const/4 v3, 0x1

    goto :goto_0

    .line 54
    .end local v1    # "keyPair":Ljava/security/KeyPair;
    .end local v2    # "keyPairGen":Ljava/security/KeyPairGenerator;
    :catch_0
    move-exception v3

    move-object v0, v3

    .local v0, "e":Ljava/lang/Exception;
    move v3, v4

    .line 55
    goto :goto_0
.end method

.method public generateRsaPrivateKey(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 5
    .param p1, "modulus"    # Ljava/lang/String;
    .param p2, "privateExponent"    # Ljava/lang/String;

    .prologue
    .line 97
    :try_start_0
    new-instance v2, Ljava/math/BigInteger;

    invoke-direct {v2, p1}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V

    .line 98
    .local v2, "m":Ljava/math/BigInteger;
    new-instance v0, Ljava/math/BigInteger;

    invoke-direct {v0, p2}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V

    .line 99
    .local v0, "e":Ljava/math/BigInteger;
    const-string v3, "RSA"

    invoke-static {v3}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;

    move-result-object v3

    new-instance v4, Ljava/security/spec/RSAPrivateKeySpec;

    invoke-direct {v4, v2, v0}, Ljava/security/spec/RSAPrivateKeySpec;-><init>(Ljava/math/BigInteger;Ljava/math/BigInteger;)V

    invoke-virtual {v3, v4}, Ljava/security/KeyFactory;->generatePrivate(Ljava/security/spec/KeySpec;)Ljava/security/PrivateKey;

    move-result-object v1

    .line 100
    .local v1, "key":Ljava/security/PrivateKey;
    invoke-static {v1}, Lrexsee/security/RexseeSecurity;->key2string_(Ljava/security/Key;)Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v3

    .line 102
    .end local v0    # "e":Ljava/math/BigInteger;
    .end local v1    # "key":Ljava/security/PrivateKey;
    .end local v2    # "m":Ljava/math/BigInteger;
    :goto_0
    return-object v3

    .line 101
    :catch_0
    move-exception v3

    move-object v0, v3

    .line 102
    .local v0, "e":Ljava/lang/Exception;
    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "[Exception]"

    invoke-direct {v3, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v0}, Ljava/lang/Exception;->getLocalizedMessage()Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    goto :goto_0
.end method

.method public generateRsaPublicKey(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 5
    .param p1, "modulus"    # Ljava/lang/String;
    .param p2, "publicExponent"    # Ljava/lang/String;

    .prologue
    .line 87
    :try_start_0
    new-instance v2, Ljava/math/BigInteger;

    invoke-direct {v2, p1}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V

    .line 88
    .local v2, "m":Ljava/math/BigInteger;
    new-instance v0, Ljava/math/BigInteger;

    invoke-direct {v0, p2}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;)V

    .line 89
    .local v0, "e":Ljava/math/BigInteger;
    const-string v3, "RSA"

    invoke-static {v3}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;

    move-result-object v3

    new-instance v4, Ljava/security/spec/RSAPublicKeySpec;

    invoke-direct {v4, v2, v0}, Ljava/security/spec/RSAPublicKeySpec;-><init>(Ljava/math/BigInteger;Ljava/math/BigInteger;)V

    invoke-virtual {v3, v4}, Ljava/security/KeyFactory;->generatePublic(Ljava/security/spec/KeySpec;)Ljava/security/PublicKey;

    move-result-object v1

    .line 90
    .local v1, "key":Ljava/security/PublicKey;
    invoke-static {v1}, Lrexsee/security/RexseeSecurity;->key2string_(Ljava/security/Key;)Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v3

    .line 92
    .end local v0    # "e":Ljava/math/BigInteger;
    .end local v1    # "key":Ljava/security/PublicKey;
    .end local v2    # "m":Ljava/math/BigInteger;
    :goto_0
    return-object v3

    .line 91
    :catch_0
    move-exception v3

    move-object v0, v3

    .line 92
    .local v0, "e":Ljava/lang/Exception;
    new-instance v3, Ljava/lang/StringBuilder;

    const-string v4, "[Exception]"

    invoke-direct {v3, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v0}, Ljava/lang/Exception;->getLocalizedMessage()Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v3

    goto :goto_0
.end method

.method public getInheritInterface(Lrexsee/core/browser/Browser;)Lrexsee/core/browser/clazz/JavascriptInterface;
    .locals 0
    .param p1, "childBrowser"    # Lrexsee/core/browser/Browser;

    .prologue
    .line 27
    return-object p0
.end method

.method public getInterfaceName()Ljava/lang/String;
    .locals 2

    .prologue
    .line 23
    new-instance v0, Ljava/lang/StringBuilder;

    iget-object v1, p0, Lrexsee/security/RexseeKeyPairGenerator;->mBrowser:Lrexsee/core/browser/Browser;

    iget-object v1, v1, Lrexsee/core/browser/Browser;->application:Lrexsee/core/application/RexseeApplication;

    iget-object v1, v1, Lrexsee/core/application/RexseeApplication;->resources:Lrexsee/core/application/Resource;

    iget-object v1, v1, Lrexsee/core/application/Resource;->prefix:Ljava/lang/String;

    invoke-static {v1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v1

    invoke-direct {v0, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v1, "KeyPairGenerator"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method public getNewInterface(Lrexsee/core/browser/Browser;)Lrexsee/core/browser/clazz/JavascriptInterface;
    .locals 1
    .param p1, "childBrowser"    # Lrexsee/core/browser/Browser;

    .prologue
    .line 31
    new-instance v0, Lrexsee/security/RexseeKeyPairGenerator;

    invoke-direct {v0, p1}, Lrexsee/security/RexseeKeyPairGenerator;-><init>(Lrexsee/core/browser/Browser;)V

    return-object v0
.end method

.method public getPrivateKey()Ljava/lang/String;
    .locals 1

    .prologue
    .line 75
    iget-object v0, p0, Lrexsee/security/RexseeKeyPairGenerator;->mPrivateKey:Ljava/lang/String;

    return-object v0
.end method

.method public getPublicKey()Ljava/lang/String;
    .locals 1

    .prologue
    .line 72
    iget-object v0, p0, Lrexsee/security/RexseeKeyPairGenerator;->mPublicKey:Ljava/lang/String;

    return-object v0
.end method
